package com.hongawen.stream;

import com.hongawen.pojo.Staff;
import com.hongawen.pojo.Student;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年04月19日 20:44
 */
public class TestStream {

    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("Mike", 10, "male", 88));
        students.add(new Student("Jack", 10,"male", 90));
        students.add(new Student("Lucy", 12,"female", 100));
        students.add(new Student("Jessie", 12,"female", 78));
        students.add(new Student("Allon", 16,"female", 92));
        students.add(new Student("Alis", 16,"female", 50));
        Map<Boolean, List<Student>> partitionByScore = students.stream().collect(Collectors.partitioningBy(x -> x.getScore() > 80));
        System.out.println("将学生按照考试成绩80分以上分区：");
        partitionByScore.forEach((k,v ) -> {
            System.out.print(k ? "80分以上：" : "80分以下：");
            String names = v.stream().map(Student::getName).collect(Collectors.joining(","));
            System.out.println(names);
        });
    }
    
}
